Shiny is an R package which combines R programming with the interactivity of the web.
install.packages("shiny")
Methods for Use
The shiny package, created by RStudio, enables users to not only use interactive applications created by others, but to build them as well.
Easiest Method
The ability to use a shiny app online is one of the most useful features of the package. All of the R code is executed on a remote computer which sends the results over a live http connection. Very little is required of the user in order to obtain results.
No Internet required once configured
The online method may be easy for the user, but it does require a significant amount of additional effort for the creator. We won’t get into those details here! The local method, however simply requires the creator to share a single app.R file. It is the user which needs to put forth the additional effort.
Online:
Local:
Online apps such as the Region 11 Web App are useful tools, available for all to use during soil survey, ecological site development, or other evaluations. The Region 11 app is however limited to data which is already available online, such as SDA (Soil Data Access) and NASIS (National Soil Information System) Web Reports . It is also relient on the successful operation of those data systems. If the NASIS Web Reports or SDA is down for maintanence, the app fails. Local apps have the ability to leverage local data systems more easily like NASIS or other proprietary data.
When you run into trouble, there are a few steps you can take on your own to get things working again. This list may help you get your issue resolved. If not, contact me and I can assist.
Shiny apps are extremely versatile, they can be embedded into presentations, markdown, or html. Those same formats can also be embedded in to a shiny app. This is a very simple example of a shiny app which consists of an interactive dropdown menu which controls what region is displayed in the bar chart. Let’s take a look at the code.
shinyApp(
ui =
# Rely on the 'WorldPhones' dataset in the datasets
# package (which generally comes preloaded).
library(datasets)
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
titlePanel("Telephones by region"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("region", "Region:",
choices=colnames(WorldPhones)),
hr(),
helpText("Data from AT&T (1961) The World's Telephones.")
),
# Create a spot for the barplot
mainPanel(
plotOutput("phonePlot")
)
)
)
server =
# Rely on the 'WorldPhones' dataset in the datasets
# package (which generally comes preloaded).
library(datasets)
# Define a server for the Shiny app
function(input, output) {
# Fill in the spot we created for a plot
output$phonePlot <- renderPlot({
# Render a barplot
barplot(WorldPhones[,input$region]*1000,
main=input$region,
ylab="Number of Telephones",
xlab="Year")
})
}
)
Shiny apps consist of a ui and a server. The ui is the part of the shiny app the user sees, the user interface. In the ui, a user can choose or enter inputs for processing and viewing the results. The server takes the inputs, performs some data processing and rendering of those inputs and generates the outputs for the ui to display.
What new features in RStudio are available for you to use once the shiny package is installed?
The Region 11 Web App uses which 2 data sources for its reports?
If an error occurs while using the Region 11 Web App, what should you do?
Poll: A shiny app consists of:
The NASIS Reports button is a link to a master list of NASIS Web reports for Regions 10 and 11.
The query method option allows you to choose between MUKEY, NATSYM, MUNAME. It also has a radio button for switching between flooding and ponding.
Plots and Data Tables are on separate sub-menu items.
Same options as the Water Table Tab except no radio button. The query method option allows you to choose between MUKEY, NATSYM, MUNAME.
Plots and Data Tables are on separate sub-menu items.
The project report can accept multiple projects. Use the semicolon (;) as a separator. You can also save a copy of the report by clicking the link below the submit button.
Type in Year, type or select office and type project name for the Project extent query. Zoom and pan to view extent. Use the layers button to change the basemap or toggle layers. Click the link below the submit button to download a .zip containing the extent as a ESRI shapefile.
Enter an office symbol to generate a long range plan report.
Enter the national mapunit symbol to plot all available interpretations for the mapunit from SDA.
Use the project report to generate a report on a project in your own area. Save the results and explain the results of pH plots for one of your components.
Map an extent of a project. How many layers are available to choose from as a basemap? How many layers can be toggled on or off?
Choose an office to generate a long range plan. What is the highest acreage project for 2025?
Plotly. 2015. “R Graphing Library | Plotly - Make Interactive, Publication-Quality Graphs Online.” https://plot.ly/r/.
RStudio. 2014. “Shinydashboard - Use Shiny to Create Dashboards.” https://rstudio.github.io/shinydashboard/.
———. 2016a. “Leaflet for R - Integrate and Control Leaflet Maps in R.” https://rstudio.github.io/leaflet/.
———. 2016b. “R Markdown - Make Documents, Reports and Presentations.” http://rmarkdown.rstudio.com/.
———. 2017a. “Shiny - Interactive Web Applications.” http://shiny.rstudio.com.
———. 2017b. “shinyapps.io - Share Your Shiny Applications Online.” http://www.shinyapps.io/.
———. 2018. “DT: An R interface to the DataTables library - Display Interactive Tables.” https://rstudio.github.io/DT/.